// export const baseUrl = 'https://human.ykpin.com'
// export const baseUrl = 'http://123.206.49.253:6134'
export const saasappid = '2024010100000001'
export const dateNum = '20250901'
import { baseUrlDate, wxUrlDate } from './env.js'

export const baseUrl = baseUrlDate
export const chateUrl = wxUrlDate

export const http = {
	getData: (data : string) => {
		return uni.getStorageSync(data);
	},
	setData: (data : string, value : any) => {
		return uni.setStorageSync(data, value);
	},
	clearData: (data : string) => {
		return uni.removeStorageSync(data);
	},
	removeAll: () => {
		return uni.clearStorageSync();
	},
	request: (url : string, data : any, type : any) => {
		return new Promise((resolve, reject) => {
			uni.request({
				method: type,
				url: baseUrl + url,
				data: data,
				header: {
					'Authorization': 'Bearer ' + http.getData('token'),
					'version': uni.getStorageSync('appVerision') || ''
				},
				dataType: 'json',
			}).then((res : any) => {
				uni.hideLoading()
				if (res.data.code == 500) {
					resolve(res.data)
				}
				// if (res.data.code == 600) {
				// 	uni.navigateTo({
				// 		url: '/subpackages/findJob/bildingPhone'
				// 	})
				// 	resolve(res.data)
				// 	return
				// }

				if (res.data.code == 401) {
					setTimeout(() => {
						uni.showToast({
							title: '请先登录！',
							icon: "none",
							mask: true
						})
					}, 100)

					setTimeout(() => {
						uni.reLaunch({
							url: "/pages/login/login"
						})
					}, 1500)

					return
				}
				resolve(res.data);
			}).catch(error => {
				uni.hideLoading()
				reject(error)
			})
		});
	},

	get: (url : any, data ?: any) => {
		return new Promise((resolve, reject) => {
			http.request(url, data, 'GET').then(res => {
				resolve(res);
			}).catch(error => {
				reject(error)
			})
		});
	},
	post: (url : any, data ?: any) => {
		return new Promise((resolve, reject) => {
			http.request(url, data, 'POST').then(res => {
				resolve(res);
			}).catch(error => {
				reject(error)
			})
		});
	},
	upload: (filePath ?: string, data ?: any) => {
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				url: baseUrl + '/api/upload/minishop',
				filePath: filePath,
				name: 'file',
				formData: data,
				header: {
					'saasappid': saasappid,
					'Authorization': 'Bearer ' + http.getData('token')
				},
				success: (res) => {
					const data = JSON.parse(res.data)
					resolve(data)
				},
				fail: (error) => {
					reject(error)
				}
			});
		})
	}
}